package com.yf.controller.api;

import com.yf.annotation.LoginUser;
import com.yf.entity.UserEntity;
import com.yf.response.R;
import com.yf.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * User: Administrator
 * Date: 2018-12-12
 * Time: 9:44
 * Description:
 */
@RestController
@RequestMapping("/api")
public class ApiHomeController {

    @Autowired
    private BannerService bannerService;

    @Autowired
    private ExperienceShareService experienceShareService;

    @Autowired
    private UserService userService;

    @Autowired
    private RecordService recordService;

    @Autowired
    private SignInService signInService;

    @Autowired
    private NoticeService noticeService;


    /**
     * 首页banner图
     *
     */
    @GetMapping("/home/banner")
    public R<List> banner(){
        return R.ok(bannerService.getAll());
    }

    /**
     *
     * 经验分享列表
     */
    @GetMapping("/home/experience/list")
    public R<List> experienceList(){
        return R.ok(experienceShareService.getAll());
    }

    /**
     * 个人中心，基本信息
     * @param userEntity
     * @return
     */
    @GetMapping("/user/info")
    public R userInfo(@LoginUser UserEntity userEntity){
        return R.ok(userService.getInfo(userEntity.getId()));
    }

    /**
     * 保存基本信息
     */
    @PostMapping("/user/saveInfo")
    public R saveInfo(@LoginUser UserEntity userEntity, String sex, String phone, String realName, String idNumber, Date birthday, String address){
        userService.saveInfo(userEntity.getId(), sex, phone, realName, idNumber, birthday, address);
        return R.ok();
    }

    /**
     * 个人中心，健康档案
     * @param userEntity
     * @return
     */
    @GetMapping("/user/record")
    public R record(@LoginUser UserEntity userEntity){
        return R.ok(recordService.getRecord(userEntity.getId()));
    }

    /**
     * 签到信息
     * @param
     * @return
     */
    @GetMapping("/sign/info")
    public R getSign(@LoginUser UserEntity userEntity){
        return R.ok(signInService.getSign(userEntity.getId()));
    }


    /**
     * 用户签到
     */
    @GetMapping("/sign/signIn")
    public R signIn(@LoginUser UserEntity userEntity){
        signInService.signIn(userEntity.getId());
        return R.ok();
    }


    /**
     * 消息通知
     */
    @GetMapping("/notice/get")
    public R getNotice(@LoginUser UserEntity userEntity){
        return R.ok(noticeService.getAll());
    }

}
